/*
 * @Author: 胡晓星
 * @Date: 2024-07-23 16:43:31
 * @LastEditors: 胡晓星
 * @LastEditTime: 2024-09-03 16:42:56
 * @FilePath: g:\nodePre\rsba-serve\src\modules\auth\local.strategy.ts
 * @Description: 
 */

import { Injectable } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { Strategy } from 'passport-local';
import { AuthService } from './auth.service';
import { CustomException, ErrorCode } from '@/common/exceptions/custom.exception';

@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {
  constructor(private readonly authSerevice: AuthService) {
    super();
  }

  async validate(username: string, password: string): Promise<any> {
      const user = await this.authSerevice.validateUser(username, password);
    if (!user) throw new CustomException(ErrorCode.ERR_10002);
    return user;
  }
}
